% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cces_collapse.R
\name{build_counts}
\alias{build_counts}
\title{Collapse CCES data to be analyzed in binomial model}
\usage{
build_counts(
  formula,
  data,
  keep_vars = NULL,
  name_ones_as = "yes",
  name_trls_as = "n_response",
  multiple_qIDs = FALSE,
  verbose = TRUE
)
}
\arguments{
\item{formula}{the model formula used to fit the multilevel regression model.
Should be of the form \code{y ~ x1 + x2 + (1|x3)} where y is a binary variable
and only categorical variables should be used in the random effects notation.}

\item{data}{A cleaned CCES dataset, e.g. from \link{ccc_std_demographics} which is
then combined with outcome and contextual data in \link{cces_join_slim}.
By default it expects the LHS outcome to be named \code{response}, and expects
the dataset to have that variable.
This variable must be binary or it must be a character vector that can be coerced
by \link{yesno_to_binary} into a binary variable.}

\item{keep_vars}{Variables that will be kept as a cell variable, regardless
of whether it is specified in a formula. Input as character vector.}

\item{name_ones_as}{What to name the variable that represents the number of
successes in the binomial}

\item{name_trls_as}{What to name the variable that represents the number of
trials in the binomial.}

\item{multiple_qIDs}{Does the data contain \emph{multiple} outcomes in long form and
therefore require the counts to be built for each outcome? Defaults to \code{FALSE}.}

\item{verbose}{Show warning messages? Defaults to TRUE}
}
\value{
A dataframe of cells. The following variables have fixed names and
will be assumed by \code{ccesMRPrun::fit_brms_binomial}:
\itemize{
\item \code{yes}: the number of successes observed in the cell
\item \code{n_response} the number of non-missing responses, representing the number
of trials.
}
}
\description{
Currently only is compatible with question of type \code{"yesno"}.
}
\examples{

library(dplyr)

ccc_samp_std <- ccc_samp \%>\%
  mutate(y = sample(c("For", "Against"), size = n(), replace = TRUE)) \%>\%
  ccc_std_demographics()

ccc_samp_out <- build_counts(y ~ age + gender + educ + (1|cd),
                             ccc_samp_std)

ccc_samp_out

# alternative options
build_counts(y ~ educ + (1|cd), ccc_samp_std,
             name_ones_as = "success", name_trls_as = "trials")
build_counts(y ~ educ + (1|cd), ccc_samp_std,
             keep_vars = "state")

}
